package com.zhangyang.esper;


/**
 * 分组统计每个产品的价格列表，并返回每个产品的最新价格
 * 
 * @author luonq(luonq@primeton.com)
 *
 */
public class GroupbyTest {

	public static void main(String[] args) {

//		String runtimeURI = "GroupbyTest";
//		Configuration configuration = new Configuration();
//		configuration.configure(runtimeURI);
//		EPRuntime runtime = EPRuntimeProvider.getRuntime(runtimeURI, configuration);
//
//		runtime.initialize();
//
//		// window只能用于stream的属性，不能用于stream，只有prevwindow可用于stream，详细可见SelectWindowEventTest例子
//		String epl = "select type, window(price) as priceList, last(price) as lastPrice from " + Product.class.getName()
//				+ ".win:length_batch(5) group by type";
//
//		Product p1 = new Product();
//		p1.setType("esb");
//		p1.setPrice(20);
//		System.out.println("sendEvent: " + p1);
//		runtime.getEventService().sendEventBean(p1, "com.fanxl.esper.model.Product");
//
//		Product p2 = new Product();
//		p2.setType("eos");
//		p2.setPrice(30);
//		System.out.println("sendEvent: " + p2);
//		runtime.getEventService().sendEventBean(p2, "com.fanxl.esper.model.Product");
//
//		Product p3 = new Product();
//		p3.setType("esb");
//		p3.setPrice(35);
//		System.out.println("sendEvent: " + p3);
//		runtime.getEventService().sendEventBean(p3, "com.fanxl.esper.model.Product");
//
//		Product p4 = new Product();
//		p4.setType("bps");
//		p4.setPrice(40);
//		System.out.println("sendEvent: " + p4);
//		runtime.getEventService().sendEventBean(p4, "com.fanxl.esper.model.Product");
//
//		Product p5 = new Product();
//		p5.setType("esb");
//		p5.setPrice(25);
//		System.out.println("sendEvent: " + p5);
//		runtime.getEventService().sendEventBean(p5, "com.fanxl.esper.model.Product");
//
//		compileDeploy(epl, runtime);
	}

//	public static EPStatement compileDeploy(String epl, EPRuntime runtime) {
//		try {
//			CompilerArguments args = new CompilerArguments();
//			args.getPath().add(runtime.getRuntimePath());
//			args.getOptions().setAccessModifierNamedWindow(env -> NameAccessModifier.PUBLIC); // All named windows are visibile
//			args.getConfiguration().getCompiler().getByteCode().setAllowSubscriber(true); // allow subscribers
//
//			EPCompiled compiled = EPCompilerProvider.getCompiler().compile(epl, args);
//			EPDeployment deployment = runtime.getDeploymentService().deploy(compiled);
//			return deployment.getStatements()[0];
//		} catch (Exception ex) {
//			throw new RuntimeException(ex);
//		}
//	}
}